package old_go_learn

import (
	"fmt"
)

type Student2 struct {
	name string
	age  int
}

func main() {
	i := make([]interface{}, 3)

	i[0] = 1
	i[1] = "go"
	i[2] = Student2{"mike", 118}

	//fmt.Println(i[0])

	for index, data := range i {

		//通过if实现断言
		//v,bool := data.(int)
		//fmt.Printf("v=%v,bool = %v\n",v,bool)
		//
		//if value,ok := data.(int); ok == true{
		//	fmt.Printf("x[%d] 类型为int , 内容为 %d \n",index,value)
		//}
		//
		//if value,ok := data.(string); ok == true{
		//	fmt.Printf("x[%d] 类型为string，内容为%s \n",index,value)
		//}
		//
		//if value,ok := data.(Student2); ok == true{
		//	fmt.Printf("x[%d]类型为struct, name = %s,age=%d\n",index,value.name,value.age)
		//}

		//通过switch实现断言
		switch value := data.(type) {
		case int:
			fmt.Printf("x[%d] 类型为int , 内容为 %d \n", index, value)

		case string:
			fmt.Printf("x[%d] 类型为string，内容为%s \n", index, value)

		case Student2:
			fmt.Printf("x[%d]类型为struct, name = %s,age=%d\n", index, value.name, value.age)

		}
	}
}
